#include "APP_func.h"
#include "W5500_TCP.h"

//默认关屏幕0，开屏幕1
uint8_t oled_flag=0;

//四个按键的自定义功能
//1.上传数据
//2.切换收发模式
//3.天问播报
//4.开关屏幕
void APP_key_func(void){
    Key_Type key_new=INF_key_scan();
    uint16_t temp1=APP_measure_getTemp();
    uint16_t humi1=APP_measure_getHumi();
    char temp_str1[5]={0};
    char humi_str1[5]={0};
    switch (key_new)
    {
    case KEY1:
        //上传数据
        sprintf(temp_str1,"%d",temp1);
        sprintf(humi_str1,"%d",humi1);
        W5500_Server_Start();
        W5500_Server_Send((uint8_t*)temp_str1,16);
        W5500_Server_Send((uint8_t*)humi_str1,16);
        break;
    case KEY2:
        //切换收发模式
        HAL_GPIO_TogglePin(RS485_TR_GPIO_Port,RS485_TR_Pin);
        break;
    case KEY3:
        //天问播报温度和湿度
        HAL_UART_Transmit(&huart3,(uint8_t*)"temp",4,1000);
        HAL_Delay(2000);
        INF_tianwen51_reply_temp(1,APP_measure_getTemp());
        HAL_Delay(2000);
        HAL_UART_Transmit(&huart3,(uint8_t*)"humi",4,1000);
        HAL_Delay(2000);
        INF_tianwen51_reply_humi(1,APP_measure_getHumi());
        break;
    case KEY4:
        //开关屏幕
        oled_flag=!oled_flag;
        break;
    default:
        break;
    }
}
